home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / bathtubChar.lua < prev    next >
Text File  |  2004-01-29  |  11KB  |  430 lines

  1. -- bathtub character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         print("bath character state machine onEnter");
  7.         local bathtub = getStateObjectFromID(msg.sender);
  8.         storeStateObject("bathtub", bathtub);
  9.         
  10.         storeData("initOutfit", getParent().getOutfit());
  11.  
  12.         if (bathtub) then
  13.             
  14.             -- bathtub  does exist
  15.             local actionPointName = retrieveData("actionPointName");
  16.             local actionPoint = getParent().getFreeActionPoint(bathtub, actionPointName);
  17.             
  18.             if (actionPoint) then
  19.                 -- action point is free
  20.                 getParent().lockActionPoints(bathtub);
  21.                  if (actionPointName == "water2") then
  22.                     storeData("mirrorAnims", true);
  23.                 else
  24.                     storeData("mirrorAnims", false);
  25.                 end
  26.             else
  27.                 -- action point is not free anymore
  28.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  29.                 sendMsg("emoThink", getParent().walkSO);
  30.                 exitStateMachine();
  31.             end
  32.                                     
  33.         else
  34.             -- bathtub does not exist anymore
  35.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  36.             sendMsg("emoThink", getParent().walkSO);
  37.             exitStateMachine();
  38.         end
  39.         
  40.         freeHands(getParent());
  41.     end )
  42.     
  43.     
  44.     
  45.     onExit(function(msg)
  46.         local bathtub = retrieveStateObject("bathtub");
  47. --        if (bathtub) then
  48. --            getParent().unlockActionPoints(bathtub);
  49. --            getParent().stopAllActivities(bathtub);
  50. --            removeStateObject("bathtub");
  51. --        end;
  52.  
  53.         unlockAll("bathtub");
  54.         
  55.         local water = bathtub.findChildGO("water");
  56.         if (water) then
  57.             bathtub.setChildEnable("water", false);
  58.             water.stopSkeletonAnimation();
  59.         end;    
  60.     end )
  61.     
  62.     onReturn(function(msg)
  63.         print("bath character state machine onReturn");
  64.         local actionPointName = retrieveData("actionPointName");
  65.         if (actionPointName == "enter2")  then
  66.             storeData("mirrorAnims", true);
  67.         else
  68.             storeData("mirrorAnims", false);
  69.         end
  70.         setState("undressOutside");
  71.     end )
  72.     
  73.     state("openWater")
  74.     
  75.         onEnter(function(msg)
  76.             print("openWater onEnter");            
  77.             startAnimation("bathtubWater", retrieveData("mirrorAnims"));
  78.             
  79.                         
  80.             sendDelayedMsgThis("waterSound", 1500);
  81.         end )
  82.         
  83.         onMsg("waterSound", function(msg)
  84.             local bathtub = retrieveStateObject("bathtub");
  85.             bathtub.playSound("bathWaterIn");
  86.         end )    
  87.         
  88.         onMsg("end", function(msg)
  89.             if testCancel() then
  90.                 exitStateMachine();
  91.             else
  92.                 --setState("enterTub");
  93.                 local bathtub = retrieveStateObject("bathtub");
  94.                                 
  95.                 local actionPoint = getParent().getClosestFreeActionPoint(getParent(), bathtub, {"enter1", "enter2"});
  96.                                 
  97.                 if (actionPoint) then
  98.                     if (walkToPointImmediate(actionPoint)) then
  99.                         print("enterStateMachine subwalk");
  100.                         storeData("actionPointName", actionPoint.getName());
  101.                         enterStateMachine("subwalk.walk");
  102.                     else
  103.                         print("no path found");
  104.                         getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  105.                         sendMsg("emoThink", getParent().walkSO);
  106.                         exitStateMachine();
  107.                     end
  108.                 else
  109.                     print("no action point found");
  110.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  111.                     sendMsg("emoThink", getParent().walkSO);
  112.                     exitStateMachine();
  113.                 end                
  114.             end
  115.         end )            
  116.     
  117. --        onMsg("end", function(msg)
  118. --            if testCancel() then
  119. --                exitStateMachine();
  120. --            else
  121. --                --setState("enterTub");
  122. --                local bathtub = retrieveStateObject("bathtub");
  123. --                
  124. --                exitStateMachine();
  125. --                
  126. --                local actionPoint = getParent().getClosestFreeActionPoint(getParent(), bathtub, {"enter1", "enter2"});
  127. --                if (actionPoint) then
  128. --                    if (walkToActionPoint(actionPoint)) then
  129. --                        queueStateMachine("bathtubChar.undressOutside", bathtub);
  130. --                    else
  131. --                        print("no path found");
  132. --                        getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  133. --                        sendMsg("emoThink", getParent().walkSO);
  134. --                        exitStateMachine();
  135. --                    end
  136. --                else
  137. --                    print("no action point found");
  138. --                    getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  139. --                    sendMsg("emoThink", getParent().walkSO);
  140. --                    exitStateMachine();
  141. --                end
  142. --                
  143. --                
  144. --            end
  145. --        end )    
  146.     
  147.     
  148.     -- undress outside the tub
  149.     state("undressOutside")
  150.     
  151.         onEnter(function(msg)
  152.         
  153.         
  154.             local character = getParent();        
  155.             local other, result = getDisturbingChar(character, "showNaked");
  156.             if (other) then
  157.                 exitStateMachine();
  158.                 character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  159.                 other.sendMsg("emoShameChar", character.walkSO);        
  160.                 return    
  161.             end;
  162.         
  163. --            local character = getParent();
  164. --            local others = character.getCharactersInRoom();
  165. --                    
  166. --            for c = 1, getn(others) do
  167. --                local other = others[c];
  168. --                --print("checkShyness other found");
  169. --                if (not activityPossible(character, "showInUnderwear", other)) then
  170. --                    exitStateMachine();
  171. --                    --print("checkShyness sendMsg emoShame");
  172. --                    character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  173. --                    other.sendMsg("emoShameChar", character.walkSO);        
  174. --                    return    
  175. --                end;
  176. --            end;
  177. --        
  178.         
  179.             
  180.             local bathtub = retrieveStateObject("bathtub");    
  181.             if testCancel() or bathtub.isBroken() then
  182.                 exitStateMachine();
  183.             else
  184.                 --startAnimation("ausziehen2");
  185.                 startAnimation(getChangeOutfitAnim(getParent()));
  186.                 sendDelayedMsgThis("underwear", 1600);    
  187.                 
  188.                 --local water = bathtub.loadGameObjectIntoGameObject("StandardGO","bathtubWater");
  189.                 local water = bathtub.findChildGO("water");
  190.                 bathtub.setChildEnable("water", true);
  191.                 water.startSkeletonAnimation("waves");            
  192.                 --storeStateObject("water", water);
  193.             end
  194.  
  195.         end )
  196.         
  197.         onMsg("underwear", function(msg)
  198.             getParent().changeOutfit(NOTHING);
  199.         end )
  200.         
  201.     
  202.         onMsg("end", function(msg)
  203.             if testCancel() then
  204.                 local initOutfit = retrieveData("initOutfit");        
  205.                 getParent().changeOutfit(initOutfit);
  206.                 --local water = retrieveStateObject("water");
  207.                 --removeStateObject("water");
  208.                 --water.deleteGameObject();
  209.                 
  210. --                local water = bathtub.findChildGO("water");
  211. --                bathtub.setChildEnable("water", false);
  212. --                water.stopSkeletonAnimation();    
  213.                         
  214.                 exitStateMachine();
  215.             else
  216.                 setState("enterTub");
  217.                 sendDelayedMsgThis("act", 5000);
  218.             end
  219.         end )    
  220.     
  221.             
  222.  
  223.     state("enterTub")
  224.     
  225.         onEnter(function(msg)
  226.             print("enterTub onEnter");            
  227.             startAnimation("bathtubEnter", retrieveData("mirrorAnims"));
  228.             --getParent().enableBlend(true);
  229.             sendDelayedMsgThis("splashSound", 3800);
  230.         end )
  231.         
  232.         onMsg("splashSound", function(msg)
  233.             getParent().playSound("splashSoft");
  234.         end )    
  235.  
  236.     
  237.         onMsg("end", function(msg)
  238.             if testCancel() then
  239.                 setState("exitTub");
  240.             else
  241.                 setState("lay");
  242.             end
  243.         end )    
  244.     
  245.             
  246.         
  247.     -- lay
  248.     state("lay")
  249.     
  250.         onEnter(function(msg)
  251.         
  252.             local bathtub = retrieveStateObject("bathtub");            
  253.             local bath = getParent().startActivity("bath", bathtub);
  254.             local length, scale = getActivityLength(bath);
  255.             storeData("scale", scale);
  256.             
  257.             sendDelayedMsgThis("complete", length);
  258.             --actionComplete();
  259.             
  260.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  261.             
  262.             startAnimation("bathtubLay", retrieveData("mirrorAnims"));
  263.             bathtub.loopSound("bathLoop");
  264.             
  265.             dirtify(bathtub, DIRTIFY_PER_BATH);
  266.             
  267.             
  268.         end )
  269.         
  270.         onExit(function(msg)
  271.             local bathtub = retrieveStateObject("bathtub");
  272.             getParent().stopAllActivities(bathtub);
  273.             bathtub.stopSound("bathLoop");
  274.             bathtub.playSound("bathWaterOut");
  275.         end )
  276.         
  277.         onMsg("complete", function(msg)
  278.             setState("exitTub");
  279.         end )
  280.             
  281.         onMsg("queue", function(msg)
  282.             setState("exitTub");
  283.         end )
  284.             
  285.         onMsg("end", function(msg)
  286.             startAnimation("bathtubLay", retrieveData("mirrorAnims"));
  287.         end )
  288.  
  289.         onMsg("testCancel", function(msg)
  290.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  291.                 setState("exitTub");
  292.             else
  293.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  294.             end
  295.         end )            
  296.         
  297.     -- stand up from tub
  298.     state("exitTub")
  299.     
  300.         onEnter(function(msg)
  301.             print("exitTub onEnter");
  302.             startAnimation("bathtubExit", retrieveData("mirrorAnims"));
  303.             sendDelayedMsgThis("splashSound", 1000);
  304.             sendDelayedMsgThis("towel", 3000);
  305.         end )
  306.         
  307.         onMsg("splashSound", function(msg)
  308.             local bathtub = retrieveStateObject("bathtub");
  309.             bathtub.playSound("splashSoft");
  310.         end )
  311.         
  312.         onMsg("towel", function(msg)
  313.             getParent().changeOutfit(TOWEL);
  314.         end )
  315.     
  316.         onMsg("end", function(msg)
  317.             print("exitTub onExit");            
  318. --            local initOutfit = retrieveData("initOutfit");        
  319. --            print("   initOutfit onExit", initOutfit);            
  320. --            getParent().changeOutfit(initOutfit);
  321.             --local water = retrieveStateObject("water");
  322.             --water.deleteGameObject();
  323.             --getParent().enableBlend(false);
  324. --            local bathtub = retrieveStateObject("bathtub");
  325. --            
  326. --            local water = bathtub.findChildGO("water");
  327. --            water.stopSkeletonAnimation();            
  328. --            bathtub.setChildEnable("water", false);
  329.             
  330.  
  331.             exitStateMachine();
  332.         end )
  333.         
  334.  
  335.     state("cleanStart")
  336.     
  337.         onEnter(function(msg)
  338.             -- grab sponge
  339.             print("cleanStart onEnter");
  340.             local sponge = getParent().loadGameObject("StandardGO","sponge");
  341.             getParent().attachRightObjectHolder(sponge);
  342.             storeStateObject("sponge", sponge);
  343.             startAnimation("cleanBathtubStart");            
  344.         end )
  345.     
  346.         onMsg("end", function(msg)
  347.             if (testCancel()) then
  348.                 exitStateMachine();
  349.             else
  350.                 setState("clean");
  351.             end
  352.         end )    
  353.  
  354.         
  355.     -- clean up 
  356.     state("clean")
  357.     
  358.         onEnter(function(msg)
  359.             local bathtub = retrieveStateObject("bathtub");
  360.             local clean = getParent().startActivity("clean", bathtub);
  361.             local length, scale = getActivityLength(clean);
  362.             storeData("scale", scale);
  363.                         
  364.             startAnimation("cleanBathtubLoop", false, scale);
  365.             bathtub.playSound("cleanBathtub");
  366.             
  367.                         
  368.             --sendDelayedMsgThis("complete", length);
  369.             this.actionComplete();
  370.             
  371.         end )
  372.         
  373.         
  374.         onExit(function(msg)
  375.             local bathtub = retrieveStateObject("bathtub");
  376.             --bathtub.stopSound("cleanBathtub");
  377.         end )    
  378.         
  379.         
  380. --        onMsg("cancel", function(msg)
  381. --            
  382. --            getParent().stopActivity("clean", retrieveStateObject("bathtub"));
  383. --            setState("cleanEnd");
  384. --        end )    
  385. --    
  386. --        onMsg("gueue", function(msg)
  387. --            sendMsgThis("complete");
  388. --        end )    
  389.  
  390.         onMsg("complete", function(msg)            
  391.             getParent().stopActivity("clean", retrieveStateObject("bathtub"));
  392.             setState("cleanEnd");
  393.         end )    
  394.     
  395.         onMsg("end", function(msg)
  396.             local bathtub = retrieveStateObject("bathtub");
  397.             local dirt = bathtub.getDirtiness();
  398.             if (testCancel() or dirt<0.01) then
  399.                 sendMsgThis("complete");
  400.             else
  401.                 local scale = retrieveData("scale");
  402.                 startAnimation("cleanBathtubLoop", false, scale);            
  403.                 bathtub.playSound("cleanBathtub");
  404.                 clean(bathtub, CLEAN_PER_LOOP);            
  405.             end
  406.         end )    
  407.                     
  408.         
  409.     state("cleanEnd")
  410.     
  411.         onEnter(function(msg)
  412.             -- remove sponge
  413.             local sponge = getParent().getRightHeldObject()
  414.             getParent().detachRightObjectHolder();
  415.             if (sponge) then sponge.deleteGameObject(); end
  416.             removeStateObject("sponge");
  417.  
  418.             startAnimation("cleanBathtubEnd");            
  419.         end )
  420.     
  421.         onMsg("end", function(msg)
  422.             if (not testCancel()) then queueNextClean(getParent()) end;
  423.             exitStateMachine();
  424.         end )    
  425.  
  426.  
  427.  
  428.             
  429.     
  430. endStateMachine()